# 缓存工具类
import os
from pathlib import Path


class CacheUtil:
    @staticmethod
    def build_storage_uri(config):

        driver = config.CACHE_DRIVER
        host = config.CACHE_HOST
        port = config.CACHE_PORT
        password = config.CACHE_PASSWORD

        if driver == "redis":
            # 依赖库:flask-redis Redis URI,默认端口6379 格式: redis://[:password@]host:port/db
            db = config.CACHE_DB
            auth = f":{password}@" if password else ""
            return f"redis://{auth}{host}:{port}/{db}"
        elif driver == "memcached":
            # 依赖库:pymemcache Memcached URI,默认端口12121 格式: memcached://host:port,host:port
            return f"memcached://{host}:{port}"
        elif driver == "mongodb":
            # 依赖库:pymongo MongoDB URI,默认端口27017 格式: mongodb://host:27017/db
            return f"mongodb://{host}:{port}/db"
        else:
            # 默认内存存储（不推荐生产环境）
            return "memory://"
